package castledefense.logic.buildings;

import castledefense.data.BuildingData;
import castledefense.data.GameData;
import castledefense.logic.Map;

public class Castle extends Building {

	protected int[] upgradeLevel = { 0, 0, 0, 0 };
	protected double repair = 0.0005;

	public Castle(Map map, int posX, int posY, int type) {
		super(map, posX, posY, 5, type);
	}

	@Override
	public void upgrade(int newType) {
		if (upgradeLevel[newType] < BuildingData.maxUpgrades) {
			int upCost = BuildingData.getUpgradeCost(newType,
					upgradeLevel[newType]);
			if (BuildingData.money >= upCost) {
				BuildingData.money -= upCost;
				upgradeLevel[newType]++;
				if (newType == GameData.fire) {
				} else if (newType == GameData.water) {
					repair *= 2;
				} else if (newType == GameData.earth) {
					double tmp = life / initialLife;
					initialLife *= 2;
					life = tmp * initialLife;
				} else if (newType == GameData.air) {
					BuildingData.moneyGeneration *= 2;
				}
			}
		}
	}

	public double getRegeneration() {
		return repair;
	}

	public void update(int deltaTime) {
		life = life < initialLife ? life + repair * deltaTime : initialLife;
	}

	public double getInitialLife() {
		return initialLife;
	}

	public double getLife() {
		return life;
	}

}
